import { createRouter, createWebHistory } from 'vue-router'
// 导入
import routes from "../router/route.js"

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})
//注册 全局前置守卫函数
router.beforeEach((to,from,next)=>{
  //获取token
  var token = sessionStorage.getItem('token');
  //判断是否是跳转到首页
  if( to.path == '/admin'){
    if( token ){ //已登录, 放行
      next();
    }
    else{ //未登录, 跳转到登录
      console.log(1);
      next("/Login")
    } 
  }
  else {
    next()
  }
})
export default router
